// SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
// Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef NVIDIA_GXF_STD_RECEIVER_HPP
#define NVIDIA_GXF_STD_RECEIVER_HPP

#include <set>
#include "gxf/std/queue.hpp"
#include "gxf/std/transmitter.hpp"

namespace nvidia {
namespace gxf {

// Interface for receiving entities.
class Receiver : public Queue {
 public:
  // Receives the next entity from the main stage.
  virtual gxf_result_t receive_abi(gxf_uid_t* uid) = 0;

  // The total number of entities which have recently arrived but are not yet on the main stage.
  virtual size_t back_size_abi() = 0;

  // Peeks into back stage
  virtual gxf_result_t peek_back_abi(gxf_uid_t* uid, int32_t index) = 0;

  // Moves entities which recently arrived to the main stage.
  virtual gxf_result_t sync_abi() = 0;

  virtual gxf_result_t sync_io_abi() { return GXF_SUCCESS; }

  virtual gxf_result_t wait_abi() { return GXF_SUCCESS; }

  Expected<Entity> receive();

  size_t back_size();

  Expected<void> sync();

  Expected<void> sync_io();

  Expected<void> wait();

  Expected<Entity> peekBack(int32_t index = 0);

  Expected<void> setTransmitter(Handle<Transmitter> tx);

 private:
  std::set<Handle<Transmitter>> connected_transmitters_;
};

}  // namespace gxf
}  // namespace nvidia

#endif
